

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/my-blog/img/fluid.png">
  <link rel="icon" href="/my-blog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="木舟">
  <meta name="keywords" content="python Vue Test 测试开发 自动化测试">
  
    <meta name="description" content="为什么学pythonPython，拥有入门简单、跨平台运行、生态丰富等点点。 如今已渗透到互联网it行业的各个分支，如：人工智能、后端开发、桌面应用、爬虫、运营、测试。 就测试而言，python在自动化测试、测试工具开发等方面，生态丰富性以及编写速度上远远优于其他语言。 而不论是从个人工作效率上还是从跳槽找工作上，python都是提升个人技能的最优选择，也是回报来的最快最高的选择。 环境配置 Py">
<meta property="og:type" content="article">
<meta property="og:title" content="Python基础">
<meta property="og:url" content="https://walker_kwu.gitee.io/my-blog/2022/11/16/python/basic/base/">
<meta property="og:site_name" content="My Blog">
<meta property="og:description" content="为什么学pythonPython，拥有入门简单、跨平台运行、生态丰富等点点。 如今已渗透到互联网it行业的各个分支，如：人工智能、后端开发、桌面应用、爬虫、运营、测试。 就测试而言，python在自动化测试、测试工具开发等方面，生态丰富性以及编写速度上远远优于其他语言。 而不论是从个人工作效率上还是从跳槽找工作上，python都是提升个人技能的最优选择，也是回报来的最快最高的选择。 环境配置 Py">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-11-16T06:14:25.000Z">
<meta property="article:modified_time" content="2023-05-23T10:37:53.267Z">
<meta property="article:author" content="木舟">
<meta property="article:tag" content="测试开发">
<meta property="article:tag" content="Python基础">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>Python基础 - My Blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/my-blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/my-blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/my-blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"walker_kwu.gitee.io","root":"/my-blog/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/my-blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/my-blog/js/utils.js" ></script>
  <script  src="/my-blog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/my-blog/">
      <strong>木舟</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/my-blog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Python基础"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        木舟
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-11-16 14:14" pubdate>
          2022年11月16日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          10k 字
        
      </span>
    

    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Python基础</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2023年5月23日 晚上
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="为什么学python"><a href="#为什么学python" class="headerlink" title="为什么学python"></a>为什么学python</h1><p>Python，拥有入门简单、跨平台运行、生态丰富等点点。</p>
<p>如今已渗透到互联网it行业的各个分支，如：人工智能、后端开发、桌面应用、爬虫、运营、测试。</p>
<p>就测试而言，python在自动化测试、测试工具开发等方面，生态丰富性以及编写速度上远远优于其他语言。</p>
<p>而不论是从个人工作效率上还是从跳槽找工作上，python都是提升个人技能的最优选择，也是回报来的最快最高的选择。</p>
<h1 id="环境配置"><a href="#环境配置" class="headerlink" title="环境配置"></a>环境配置</h1><ul>
<li>Pycharm，社区版即可，主要是免费</li>
<li>python，推荐3.6及以上版本</li>
<li>pip，需要配置好镜像源，安装库的时候更快速，教程可参考:</li>
</ul>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/sinat_21591675/article/details/82770360">https://blog.csdn.net/sinat_21591675/article/details/82770360</a></p>
</blockquote>
<h1 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h1><h2 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h2><blockquote>
<p>任何数据类型以及数据结构都可以通过str()进行转化成字符串<br>转化过后的字符串，可以通过eval()函数进行还原，还有一个兄弟叫：exec()<br>eval和exec，对于初学者来说，可以简单记个印象，这两个函数初学阶段是用不到的。</p>
</blockquote>
<h3 id="创建方式"><a href="#创建方式" class="headerlink" title="创建方式"></a>创建方式</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 一对单、双引号创建</span><br><span class="hljs-comment"># python有一种建议规范：单引号一般用作非中文、双引号一般用作中文</span><br>i = <span class="hljs-string">&#x27;str&#x27;</span><br>i = <span class="hljs-string">&quot;str&quot;</span><br><br><span class="hljs-comment"># 三对单、双引号创建</span><br><span class="hljs-comment"># 区别于【一对】, 这种创建方式使输出的内容换行</span><br><br><span class="hljs-comment"># 不换行</span><br>i = <span class="hljs-string">&#x27;&#x27;&#x27;str&#x27;&#x27;&#x27;</span><br>i = <span class="hljs-string">&quot;&quot;&quot;str&quot;&quot;&quot;</span><br><br><span class="hljs-comment"># 可换行</span><br>i = <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">str</span><br><span class="hljs-string">str</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br><br>i = <span class="hljs-string">&#x27;&#x27;&#x27;</span><br><span class="hljs-string">str</span><br><span class="hljs-string">str</span><br><span class="hljs-string">&#x27;&#x27;&#x27;</span><br></code></pre></td></tr></table></figure>


<h3 id="操作方式"><a href="#操作方式" class="headerlink" title="操作方式"></a>操作方式</h3><h4 id="拼接与转换"><a href="#拼接与转换" class="headerlink" title="拼接与转换"></a>拼接与转换</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 字符串是可以通过 + 进行拼接的，前提是拼接两者必须都是字符串</span><br>m = <span class="hljs-string">&quot;木&quot;</span><br>z = <span class="hljs-string">&quot;舟&quot;</span><br><span class="hljs-built_in">print</span>(m + z)  <span class="hljs-comment"># 木舟</span><br><br><br><span class="hljs-comment"># 如果字符串的值为数字，可以通过int函数进行转化成整型，浮点型则可以通过float</span><br><span class="hljs-comment"># type函数可以用来查看变量的数据类型</span><br>i = <span class="hljs-string">&#x27;1&#x27;</span><br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">int</span>(i)) <span class="hljs-comment"># 输出为整型的1</span><br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">type</span>(<span class="hljs-built_in">int</span>(i))) <span class="hljs-comment"># class:int</span><br></code></pre></td></tr></table></figure>

<h4 id="下标取值与切片"><a href="#下标取值与切片" class="headerlink" title="下标取值与切片"></a>下标取值与切片</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 字符串与数组类似，是可以通过for循环进行迭代的</span><br><span class="hljs-comment"># ps：可迭代对象都是可以通过下标进行取值的, 下标起始为0，0对应着就是第一位, 如果下标是负数，则起始为-1，对应倒数最后一位</span><br>i = <span class="hljs-string">&#x27;muzho&#x27;</span><br><span class="hljs-built_in">print</span>(i[<span class="hljs-number">0</span>]) <span class="hljs-comment"># m</span><br><br><span class="hljs-comment"># 切片, 遵循准则：左取右不拿</span><br><span class="hljs-built_in">print</span>(i[<span class="hljs-number">0</span>:<span class="hljs-number">2</span>]) <span class="hljs-comment"># mu</span><br><span class="hljs-built_in">print</span>(i[<span class="hljs-number">2</span>:<span class="hljs-number">4</span>]) <span class="hljs-comment"># zh</span><br><span class="hljs-built_in">print</span>(i[<span class="hljs-number">1</span>:]) <span class="hljs-comment"># uzho</span><br><span class="hljs-built_in">print</span>(i[:<span class="hljs-number">3</span>]) <span class="hljs-comment"># muz</span><br><span class="hljs-built_in">print</span>(i[:-<span class="hljs-number">2</span>]) <span class="hljs-comment"># 这里的-2对应倒数第二位，根据左取右不拿原则，muz</span><br><br><br><span class="hljs-comment"># 切片-步长</span><br><span class="hljs-comment"># 切片可接收三个参数，以冒号:作为分割，第三个参数为步长,默认为1，可取负数</span><br><span class="hljs-built_in">print</span>(i[<span class="hljs-number">0</span>:<span class="hljs-number">5</span>:<span class="hljs-number">2</span>]) <span class="hljs-comment"># 从第一个元素开始，每两元素取一次，mzo</span><br><br><span class="hljs-comment"># 步长负数，一般用作反转，此方法对数组同样有效</span><br><span class="hljs-built_in">print</span>(i[::-<span class="hljs-number">1</span>]) <span class="hljs-comment"># 负数意思就是倒着走，ohzum</span><br></code></pre></td></tr></table></figure>

<h4 id="f-string"><a href="#f-string" class="headerlink" title="f-string"></a>f-string</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># f-string在功能方面不逊于传统的占位符写法和format函数，同时性能又优于二者，且使用起来也更加简洁明了，因此对于Python3.6及以后的版本，推荐使用f-string进行字符串格式化。</span><br><span class="hljs-comment"># 用法，更多用法：https://blog.csdn.net/sunxb10/article/details/81036693</span><br>sex = <span class="hljs-string">&quot;男的&quot;</span><br>i = <span class="hljs-string">f&quot;木舟的性别是<span class="hljs-subst">&#123;sex&#125;</span>&quot;</span> <span class="hljs-comment"># 没错就是这么简单，一般用到的就是这种</span><br><br><span class="hljs-comment"># 占位符的用法可参考：https://www.imooc.com/article/50597</span><br><span class="hljs-comment"># format自从f-string出现后，用的就比较少了，但还是用使用场景的，用法可参考: https://www.runoob.com/python/att-string-format.html</span><br></code></pre></td></tr></table></figure>

<p>一般来说，变量填充，我们使用 f-string 就足够用了。</p>
<p>其十分便捷的使用方式，值得我们掌握。</p>
<h3 id="内置函数"><a href="#内置函数" class="headerlink" title="内置函数"></a>内置函数</h3><h4 id="常用函数（必会）"><a href="#常用函数（必会）" class="headerlink" title="常用函数（必会）"></a>常用函数（必会）</h4><p>以下介绍的几个函数，在实际编程中使用较多，应用场景较广，所以是必会的。</p>
<h5 id="split"><a href="#split" class="headerlink" title="split"></a>split</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># split</span><br><span class="hljs-comment"># 用法, 根据特定字符进行字符串切割，不论如何，最后肯定返回的是一个数组</span><br>i = <span class="hljs-string">&#x27;m|u|z|h|o|u&#x27;</span><br><span class="hljs-built_in">print</span>(i.split(<span class="hljs-string">&#x27;|&#x27;</span>)) <span class="hljs-comment"># 以管道符|进行切割，返回：[&#x27;m&#x27;, &#x27;u&#x27;, &#x27;z&#x27;, &#x27;h&#x27;, &#x27;o&#x27;, &#x27;u&#x27;]</span><br><br><span class="hljs-comment"># 如果切割字符不存在与被切割字符串中</span><br><span class="hljs-built_in">print</span>(i.split(<span class="hljs-string">&#x27;&amp;&#x27;</span>)) <span class="hljs-comment"># 上面说过，不论如何都会返回数组，返回：[&#x27;m|u|z|h|o|u&#x27;]</span><br><br><span class="hljs-comment"># 切割次数，第一个参数接收的是切割字符，第二个参数接收的切割次数，默认为全部切割</span><br><span class="hljs-built_in">print</span>(i.split(<span class="hljs-string">&#x27;|&#x27;</span>, <span class="hljs-number">2</span>)) <span class="hljs-comment"># 切割两次，返回：[&#x27;m&#x27;, &#x27;u&#x27;, &#x27;z|h|o|u&#x27;]</span><br></code></pre></td></tr></table></figure>

<h5 id="join"><a href="#join" class="headerlink" title="join"></a>join</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># join, 和split其实是一对冤家，split负责按照切割字符将字符串切割成数组，join负责将拼接字符将数组转化成字符串</span><br><span class="hljs-comment"># 用法，根据特定字符将数组中的元素拼接成字符串</span><br>i = [<span class="hljs-string">&#x27;m&#x27;</span>, <span class="hljs-string">&#x27;u&#x27;</span>, <span class="hljs-string">&#x27;z&#x27;</span>, <span class="hljs-string">&#x27;h&#x27;</span>, <span class="hljs-string">&#x27;o&#x27;</span>, <span class="hljs-string">&#x27;u&#x27;</span>]<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;|&#x27;</span>.join(i)) <span class="hljs-comment"># 输出：m|u|z|h|o|u</span><br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;&#x27;</span>.join(i)) <span class="hljs-comment"># 如果是空字符串，muzhou</span><br><br><span class="hljs-comment"># ps: 可以看出来，join主要是用作字符串拼接，但是根据字符串的拼接原则：拼接两者皆为字符串，所以如果被拼接数组中含有非字符串的元素，则会报错。如：</span><br>i = [<span class="hljs-string">&#x27;m&#x27;</span>, <span class="hljs-number">1</span>, <span class="hljs-string">&#x27;z&#x27;</span>, <span class="hljs-string">&#x27;h&#x27;</span>, <span class="hljs-string">&#x27;o&#x27;</span>, <span class="hljs-string">&#x27;u&#x27;</span>]<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&#x27;&#x27;</span>.join(i)) <span class="hljs-comment"># Exception，会报错</span><br></code></pre></td></tr></table></figure>

<h5 id="replace"><a href="#replace" class="headerlink" title="replace"></a>replace</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># replace</span><br><span class="hljs-comment"># 用法，将字符串中的部分字符，替换成新的字符, 可接收三个参数，第一个参数为被替换字符，第二个参数为替换字符，第三个参数为替换次数</span><br>i = <span class="hljs-string">&#x27;muzhou&#x27;</span><br><span class="hljs-built_in">print</span>(i.replace(<span class="hljs-string">&#x27;m&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>)) <span class="hljs-comment"># auzhou</span><br><span class="hljs-built_in">print</span>(i.replace(<span class="hljs-string">&#x27;m&#x27;</span>, <span class="hljs-string">&#x27;&#x27;</span>)) <span class="hljs-comment"># 替换字符为空，效果等同于去掉被替换字符，uzhou</span><br><span class="hljs-built_in">print</span>(i.replace(<span class="hljs-string">&#x27;u&#x27;</span>, <span class="hljs-string">&#x27;a&#x27;</span>, <span class="hljs-number">1</span>)) <span class="hljs-comment"># 将u替换成a，只替换一次，mazhou</span><br></code></pre></td></tr></table></figure>

<h4 id="更多函数"><a href="#更多函数" class="headerlink" title="更多函数"></a>更多函数</h4><blockquote>
<p><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/37672548">https://zhuanlan.zhihu.com/p/37672548</a></p>
</blockquote>
<h2 id="整型与浮点型"><a href="#整型与浮点型" class="headerlink" title="整型与浮点型"></a>整型与浮点型</h2><h3 id="创建方式-1"><a href="#创建方式-1" class="headerlink" title="创建方式"></a>创建方式</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 整型</span><br>i = <span class="hljs-number">1</span><br><br><span class="hljs-comment"># 浮点型</span><br>i = <span class="hljs-number">1.1</span><br><br><span class="hljs-comment"># 如果目标是值为整型或浮点型的字符串</span><br>i = <span class="hljs-built_in">int</span>(<span class="hljs-string">&#x27;1&#x27;</span>)<br>i = <span class="hljs-built_in">float</span>(<span class="hljs-string">&#x27;1.1&#x27;</span>)<br><br>i = <span class="hljs-built_in">int</span>(<span class="hljs-string">&#x27;a&#x27;</span>) <span class="hljs-comment"># exception 会报错</span><br>i = <span class="hljs-built_in">float</span>(<span class="hljs-string">&#x27;a&#x27;</span>) <span class="hljs-comment"># exception 会报错</span><br><br><span class="hljs-comment"># 整型和浮点型之间可以相互转化，整型转化成浮点型时，带有小数点后一位数0，浮点型转化成整型时，去掉小数点，不会做四舍五入</span><br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">int</span>(<span class="hljs-number">1.9</span>)) <span class="hljs-comment"># 1</span><br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">float</span>(<span class="hljs-number">1</span>)) <span class="hljs-comment"># 1.0</span><br></code></pre></td></tr></table></figure>

<h3 id="操作方式-1"><a href="#操作方式-1" class="headerlink" title="操作方式"></a>操作方式</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs python">i = <span class="hljs-number">1</span><br><span class="hljs-comment"># 加法</span><br>i = i + <span class="hljs-number">1</span><br>i += <span class="hljs-number">1</span><br><br><span class="hljs-comment"># 减法</span><br>i = i - <span class="hljs-number">1</span><br>i -= <span class="hljs-number">1</span><br><br><span class="hljs-comment"># 乘法、除法同上</span><br></code></pre></td></tr></table></figure>


<h2 id="布尔"><a href="#布尔" class="headerlink" title="布尔"></a>布尔</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 普通创建</span><br>i = <span class="hljs-literal">True</span>  <span class="hljs-comment"># 真</span><br>i = <span class="hljs-literal">False</span>  <span class="hljs-comment"># 假</span><br><br><span class="hljs-comment"># 条件对比创建</span><br><span class="hljs-number">1</span> == <span class="hljs-number">1</span>  <span class="hljs-comment"># True</span><br><span class="hljs-number">1</span> != <span class="hljs-number">2</span> <span class="hljs-comment"># True</span><br><span class="hljs-number">1</span> == <span class="hljs-number">2</span> <span class="hljs-comment"># False</span><br><span class="hljs-number">1</span> &gt; <span class="hljs-number">2</span> <span class="hljs-comment"># False</span><br><br><span class="hljs-comment"># 延申-if</span><br><span class="hljs-comment"># if [bool]  if后跟真假布尔值，我们可以经常看到 if xx == xx :</span><br><span class="hljs-comment"># xx == xx 这种类型的条件对比表达式就会生成一个布尔值。</span><br></code></pre></td></tr></table></figure>

<h1 id="数据结构"><a href="#数据结构" class="headerlink" title="数据结构"></a>数据结构</h1><blockquote>
<p>以下会介绍数据结构有：元组、数组（列表）、字典<br>可变结构：数组、字典，不可变结构：元组<br>有序结构：元组、数组<br>无序结构：字典（但是在3.6之后，字典开始变得有序，根据插入键值对的顺序进行排序）</p>
</blockquote>
<h2 id="元组"><a href="#元组" class="headerlink" title="元组"></a>元组</h2><h3 id="创建方式-2"><a href="#创建方式-2" class="headerlink" title="创建方式"></a>创建方式</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">i = (<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>)  <span class="hljs-comment"># 加上括号比较规范</span><br>i = <span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>  <span class="hljs-comment"># 这样也是可以的</span><br>i = (<span class="hljs-number">1</span>,) <span class="hljs-comment"># 如果只有一个元素时，需要在其后面增加一个逗号，否则不会生成元组，而是元素本身</span><br></code></pre></td></tr></table></figure>

<h3 id="操作方式-2"><a href="#操作方式-2" class="headerlink" title="操作方式"></a>操作方式</h3><h4 id="下标取值与切片-1"><a href="#下标取值与切片-1" class="headerlink" title="下标取值与切片"></a>下标取值与切片</h4><p>该操作与字符串的一致，可以移步至 </p>
<blockquote>
<p><a href="https://walker_kwu.gitee.io/my-blog/2022/11/16/python/basic/base/#%E4%B8%8B%E6%A0%87%E5%8F%96%E5%80%BC%E4%B8%8E%E5%88%87%E7%89%87">https://walker_kwu.gitee.io/my-blog/2022/11/16/python/basic/base/#下标取值与切片</a></p>
</blockquote>
<h4 id="增加元素"><a href="#增加元素" class="headerlink" title="增加元素"></a>增加元素</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 由于元组的不可变特性，无法对其中的元素进行修改，修改、删除元素都是不可以的</span><br><span class="hljs-comment"># 即使是增加，也只是通过拼接生成新元组的方式</span><br><span class="hljs-comment"># 也是由于元组的不可变原则，在对一些敏感数据进行存储时，起到了很好的安全保护作用</span><br><span class="hljs-comment"># 用法</span><br>i = (<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>)<br><span class="hljs-built_in">print</span>(i + (<span class="hljs-number">1</span>,)) <span class="hljs-comment"># (1,2,3,4,1)</span><br><br><span class="hljs-comment"># or __add__</span><br><span class="hljs-built_in">print</span>(i.__add__((<span class="hljs-number">1</span>,)) <span class="hljs-comment"># (1,2,3,4,1)</span><br><br><span class="hljs-comment"># 修改元素报错</span><br>i[<span class="hljs-number">0</span>] = <span class="hljs-number">2</span>  <span class="hljs-comment"># Exception</span><br></code></pre></td></tr></table></figure>

<h3 id="内置函数-1"><a href="#内置函数-1" class="headerlink" title="内置函数"></a>内置函数</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># count, 统计某个元素出现的次数</span><br>i = (<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">1</span>)<br><span class="hljs-built_in">print</span>(i.count(<span class="hljs-number">1</span>)) <span class="hljs-comment"># 2</span><br><br><span class="hljs-comment"># index, 返回指定元素的下标，如果有多个，则返回第一个的下标，没有则返回报错</span><br><span class="hljs-built_in">print</span>(i.index(<span class="hljs-number">1</span>)) <span class="hljs-comment"># 0</span><br><span class="hljs-built_in">print</span>(i.index(<span class="hljs-number">6</span>)) <span class="hljs-comment"># Exception</span><br></code></pre></td></tr></table></figure>

<h2 id="数组（列表）"><a href="#数组（列表）" class="headerlink" title="数组（列表）"></a>数组（列表）</h2><blockquote>
<p>数组是一个用来存储连续性较强、数据类型较为类似的数据的不二选择，<br>如：自动化用例<br>用元组的也可以，但是考虑到数组可以应对多种情况，优先选择数组</p>
</blockquote>
<h3 id="创建方式-3"><a href="#创建方式-3" class="headerlink" title="创建方式"></a>创建方式</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 普通创建</span><br>i = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]<br>i = <span class="hljs-built_in">list</span>(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>)<br></code></pre></td></tr></table></figure>


<h3 id="操作方式-3"><a href="#操作方式-3" class="headerlink" title="操作方式"></a>操作方式</h3><h4 id="拼接与转换-1"><a href="#拼接与转换-1" class="headerlink" title="拼接与转换"></a>拼接与转换</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 转换</span><br><span class="hljs-comment"># 字符串转化数组</span><br>i = <span class="hljs-string">&#x27;123&#x27;</span><br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">list</span>(i)) <span class="hljs-comment"># [&#x27;1&#x27;,&#x27;2&#x27;,&#x27;3&#x27;]</span><br><br><br><span class="hljs-comment"># 可迭代对象转化</span><br>i = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">tuple</span>) <span class="hljs-comment"># 将元组转化成数组</span><br>i = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">set</span>) <span class="hljs-comment"># 将集合转化成数组  集合用的较少，使用它的时候大多是用到了集合的特性：去重</span><br>i = <span class="hljs-built_in">list</span>(iterator) <span class="hljs-comment"># 将迭代器转化为数组，迭代器的概念可以私下了解一下</span><br><br><span class="hljs-comment"># 拼接，与字符串类似，两者拼接需要都是数组</span><br>i = []<br><span class="hljs-comment"># 如果数据量较少，用那种无所谓</span><br><span class="hljs-built_in">print</span>(i + []) <span class="hljs-comment"># 数组直接拼接，效率较慢</span><br><span class="hljs-built_in">print</span>(i.extand([])) <span class="hljs-comment"># 通过内置函数extand，效率较快</span><br></code></pre></td></tr></table></figure>

<h4 id="下标取值与切片-2"><a href="#下标取值与切片-2" class="headerlink" title="下标取值与切片"></a>下标取值与切片</h4><p>该操作与字符串的一致，可以移步至 </p>
<blockquote>
<p><a href="https://walker_kwu.gitee.io/my-blog/2022/11/16/python/basic/base/#%E4%B8%8B%E6%A0%87%E5%8F%96%E5%80%BC%E4%B8%8E%E5%88%87%E7%89%87">https://walker_kwu.gitee.io/my-blog/2022/11/16/python/basic/base/#下标取值与切片</a></p>
</blockquote>
<h4 id="对元素进行操作"><a href="#对元素进行操作" class="headerlink" title="对元素进行操作"></a>对元素进行操作</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs python">i = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]<br><span class="hljs-comment"># 修改元素, 根据下标进行修改</span><br>i[<span class="hljs-number">0</span>] = <span class="hljs-number">2</span>  <span class="hljs-comment"># [2,2,3]</span><br><br><span class="hljs-comment"># 增加元素-尾部添加</span><br>i.append(<span class="hljs-number">4</span>)  <span class="hljs-comment"># [1,2,3,4]</span><br><span class="hljs-comment"># 插入元素, 第一个参数为下标，第二个参数是元素值，会把元素值插入到下标之前 </span><br>i.insert(<span class="hljs-number">0</span>, <span class="hljs-number">4</span>)  <span class="hljs-comment"># [4,1,2,3]</span><br>i.insert(<span class="hljs-number">5</span>, <span class="hljs-number">4</span>)  <span class="hljs-comment"># [1,2,3,4] 如果下标不存在，则在最靠近的下标前插入</span><br><br><span class="hljs-comment"># 删除元素</span><br>i.remove(<span class="hljs-number">1</span>)  <span class="hljs-comment"># [2,3] 如果有多个相同元素，删除第一个，如果删除的元素不在数组中，则报错</span><br>i.remove(<span class="hljs-number">6</span>)  <span class="hljs-comment"># Excepiton</span><br></code></pre></td></tr></table></figure>

<h3 id="内置函数-2"><a href="#内置函数-2" class="headerlink" title="内置函数"></a>内置函数</h3><h4 id="常用函数"><a href="#常用函数" class="headerlink" title="常用函数"></a>常用函数</h4><h5 id="append"><a href="#append" class="headerlink" title="append"></a>append</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># append，在尾部增加一个元素</span><br>i = [<span class="hljs-number">0</span>]<br>i.append(<span class="hljs-number">1</span>) <span class="hljs-comment"># [0,1]</span><br></code></pre></td></tr></table></figure>

<h5 id="insert"><a href="#insert" class="headerlink" title="insert"></a>insert</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># insert, 在选中的下标前插入一个元素，如果下标不存在，则取最近下标</span><br>i = [<span class="hljs-number">0</span>]<br>i.insert(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># [2, 0]</span><br></code></pre></td></tr></table></figure>

<h5 id="extand"><a href="#extand" class="headerlink" title="extand"></a>extand</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># extand，将另一个数据进行合并</span><br>i = [<span class="hljs-number">0</span>]<br>i.extand([<span class="hljs-number">1</span>]) <span class="hljs-comment"># [0,1]</span><br></code></pre></td></tr></table></figure>

<h5 id="clear"><a href="#clear" class="headerlink" title="clear"></a>clear</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># clear ，清空数组</span><br>i = [<span class="hljs-number">0</span>]<br>i.clear() <span class="hljs-comment"># []</span><br></code></pre></td></tr></table></figure>

<h4 id="更多函数-1"><a href="#更多函数-1" class="headerlink" title="更多函数"></a>更多函数</h4><blockquote>
<p><a target="_blank" rel="noopener" href="https://www.runoob.com/python/python-lists.html">https://www.runoob.com/python/python-lists.html</a></p>
</blockquote>
<h2 id="字典"><a href="#字典" class="headerlink" title="字典"></a>字典</h2><blockquote>
<p>字典是一个用来存储唯一性较强，需要经常改动存储的数据的不二选择<br>与数组的查询做对比，字典具有哈希算法，可以通过key查找，是查询速度最快的数据结构</p>
</blockquote>
<h3 id="创建方式-4"><a href="#创建方式-4" class="headerlink" title="创建方式"></a>创建方式</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs python">i = &#123;&#125;<br>i = <span class="hljs-built_in">dict</span>() <span class="hljs-comment"># i = dict(xx=xx) -&gt; &#123;xx: xx&#125;</span><br><span class="hljs-comment"># 可接收数组，数组的每个元素必须为一个数组或元素，且其中必须含有两个元素，对应key-value</span><br>i = <span class="hljs-built_in">dict</span>([(<span class="hljs-string">&#x27;sex&#x27;</span>, <span class="hljs-string">&#x27;man&#x27;</span>), (<span class="hljs-string">&#x27;age&#x27;</span>: <span class="hljs-number">18</span>)])  <span class="hljs-comment"># &#123;&#x27;sex&#x27;: &#x27;man&#x27;, &#x27;age&#x27;: 18&#125;</span><br></code></pre></td></tr></table></figure>

<h3 id="操作方式-4"><a href="#操作方式-4" class="headerlink" title="操作方式"></a>操作方式</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs python">i = &#123;<span class="hljs-string">&#x27;sex&#x27;</span>: <span class="hljs-string">&#x27;man&#x27;</span>&#125;<br><span class="hljs-comment"># 查询dict[key]</span><br><span class="hljs-built_in">print</span>(i[<span class="hljs-string">&#x27;sex&#x27;</span>]) <span class="hljs-comment"># man</span><br><br><span class="hljs-comment"># 修改/创建dict[key] = value</span><br><span class="hljs-comment"># 如果存在key，则修改</span><br>i[<span class="hljs-string">&#x27;sex&#x27;</span>] = <span class="hljs-string">&#x27;female&#x27;</span>  <span class="hljs-comment"># &#123;&#x27;sex&#x27;: &#x27;female&#x27;&#125;</span><br><span class="hljs-comment"># 如果不存在，则创建</span><br>i[<span class="hljs-string">&#x27;age&#x27;</span>] = <span class="hljs-number">18</span> <span class="hljs-comment"># &#123;&#x27;sex&#x27;: &#x27;man&#x27;, &#x27;age&#x27;: 18&#125;</span><br><br><span class="hljs-comment"># 删除 del dict[key]</span><br><span class="hljs-keyword">del</span> i[<span class="hljs-string">&#x27;sex&#x27;</span>]  <span class="hljs-comment"># &#123;&#125;</span><br><br><span class="hljs-comment"># 如果key不存在，会报错keyError</span><br>i[<span class="hljs-string">&#x27;asdas&#x27;</span>]  <span class="hljs-comment"># Exception</span><br></code></pre></td></tr></table></figure>


<h3 id="内置函数-3"><a href="#内置函数-3" class="headerlink" title="内置函数"></a>内置函数</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs python">i = &#123;<span class="hljs-string">&#x27;sex&#x27;</span>: <span class="hljs-string">&#x27;man&#x27;</span>&#125;<br><span class="hljs-comment"># 获取</span><br><span class="hljs-comment"># keys(), 将字典中所有的key以迭代器的方式进行返回</span><br><span class="hljs-comment"># values()，将字典中所有的value以迭代器的方式进行返回, 不具有可变性质</span><br><span class="hljs-comment"># itmes(), 将字典中所有的key和value以迭代器的方式返回，其中value不具有可变性质，返回结构：((key1, value1), (key2, value2))</span><br><span class="hljs-comment"># get(), 上面说过，如果key不存在时，直接获取会报错，可以通过get方法，第一个参数接收key，第二个参数接收如果key不存在时返回的值如：</span><br>i.get(<span class="hljs-string">&#x27;xxx&#x27;</span>, <span class="hljs-literal">False</span>)  <span class="hljs-comment"># False, 因为xxx不存在这个key，所以返回False</span><br>i.get(<span class="hljs-string">&#x27;sex&#x27;</span>, <span class="hljs-literal">False</span>)  <span class="hljs-comment"># man</span><br></code></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python">i = &#123;<span class="hljs-string">&#x27;sex&#x27;</span>: <span class="hljs-string">&#x27;man&#x27;</span>&#125;<br><span class="hljs-comment"># 更新, update(),接收参数为字典，会将进行合并，如果有相同key，则覆盖，如果没有相同key，则新增</span><br>i.update(&#123;<span class="hljs-string">&#x27;sex&#x27;</span>: <span class="hljs-string">&#x27;female&#x27;</span>, <span class="hljs-string">&#x27;age&#x27;</span>: <span class="hljs-number">18</span>&#125;)  <span class="hljs-comment"># &#123;&#x27;sex&#x27;: &#x27;female&#x27;, &#x27;age&#x27;: 18&#125;</span><br></code></pre></td></tr></table></figure>

<h1 id="循环"><a href="#循环" class="headerlink" title="循环"></a>循环</h1><h2 id="for循环"><a href="#for循环" class="headerlink" title="for循环"></a>for循环</h2><blockquote>
<p>for循环的创建，依据的源头是可迭代对象，字符串、元组、数组、迭代器均为可迭代对象<br>循环执行代码块需要缩进，默认四个空格，可用tab进行缩进</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">10</span>): <span class="hljs-comment"># range 函数创建的是一个迭代器</span><br>    <span class="hljs-keyword">pass</span><br><br><span class="hljs-comment"># range, 一般接收两个参数，第三个参数为步长，与切片类似，起始为默认为0</span><br><span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>) <span class="hljs-comment"># 0,1,2,3,4</span><br><span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>,<span class="hljs-number">5</span>) <span class="hljs-comment"># 指定起始位 1,2,3,4</span><br><span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>,<span class="hljs-number">5</span>,<span class="hljs-number">2</span>) <span class="hljs-comment"># 步长为，两步取一次，0,2,4</span><br><br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>]:<br>    <span class="hljs-built_in">print</span>(i)  <span class="hljs-comment"># 循环输出 1 2 3 4</span><br><br><span class="hljs-comment"># else不仅仅适用于if，在循环中同样适用，触发条件为循环正常执行结束(不触发break)</span><br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">10</span>):<br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">else</span>:<br>    <span class="hljs-keyword">pass</span><br></code></pre></td></tr></table></figure>

<h2 id="while循环"><a href="#while循环" class="headerlink" title="while循环"></a>while循环</h2><blockquote>
<p>while循环的创建，依据的是布尔，while [bool]:<br>循环执行代码块需要缩进，默认四个空格，可用tab进行缩进</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>: <span class="hljs-comment"># 为真即可执行</span><br>    <span class="hljs-keyword">pass</span><br><br><span class="hljs-keyword">while</span> <span class="hljs-number">1</span> == <span class="hljs-number">1</span>: <span class="hljs-comment"># 执行</span><br>    <span class="hljs-keyword">pass</span><br><br><span class="hljs-keyword">while</span> <span class="hljs-number">1</span> == <span class="hljs-number">2</span>: <span class="hljs-comment"># 不执行</span><br>    <span class="hljs-keyword">pass</span><br><br><span class="hljs-comment"># else不仅仅适用于if，在循环中同样适用，触发条件为循环正常执行结束(不触发break)</span><br><span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:  <span class="hljs-comment"># 如果这里是False，那else也会触发</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">else</span>:<br>    <span class="hljs-keyword">pass</span><br></code></pre></td></tr></table></figure>

<h2 id="结束循环"><a href="#结束循环" class="headerlink" title="结束循环"></a>结束循环</h2><h3 id="continue"><a href="#continue" class="headerlink" title="continue"></a>continue</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># continue，单次结束，触发时会停止该次循环，开始下一次循环，触发时居下代码都不执行</span><br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>):<br>    <span class="hljs-keyword">if</span> i == <span class="hljs-number">1</span>:<br>        <span class="hljs-keyword">continue</span><br>    <span class="hljs-built_in">print</span>(i)  <span class="hljs-comment"># 输出：0 2 3 4</span><br></code></pre></td></tr></table></figure>

<h3 id="break"><a href="#break" class="headerlink" title="break"></a>break</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># break，整体结束，触发时会停止全部的循环</span><br><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>):<br>    <span class="hljs-keyword">if</span> i == <span class="hljs-number">1</span>:<br>        <span class="hljs-keyword">break</span><br>    <span class="hljs-built_in">print</span>(i)  <span class="hljs-comment"># 输出：0</span><br></code></pre></td></tr></table></figure>

<h1 id="条件控制"><a href="#条件控制" class="headerlink" title="条件控制"></a>条件控制</h1><h2 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 从上至下进行判断，满足其一为True则执行且跳出判断，如果所有的if、elif都不满足，触发else</span><br><span class="hljs-keyword">if</span> [<span class="hljs-built_in">bool</span>]:<br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">elif</span> [<span class="hljs-built_in">bool</span>]:<br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">else</span>:<br>    <span class="hljs-keyword">pass</span><br></code></pre></td></tr></table></figure>

<h2 id="什么叫做真？"><a href="#什么叫做真？" class="headerlink" title="什么叫做真？"></a>什么叫做真？</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 如果为整型或浮点型，不为0则为真</span><br><span class="hljs-keyword">if</span> <span class="hljs-number">1</span>:  <span class="hljs-comment"># 执行</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> <span class="hljs-number">0.1</span>:  <span class="hljs-comment"># 执行</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> <span class="hljs-number">0</span>:  <span class="hljs-comment"># 不执行</span><br>    <span class="hljs-keyword">pass</span><br><br><span class="hljs-comment"># 如果为字符串，不为空则为真</span><br><span class="hljs-keyword">if</span> <span class="hljs-string">&#x27;1&#x27;</span>: <span class="hljs-comment"># 执行，ps：空格也算是字符哦</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> <span class="hljs-string">&#x27;&#x27;</span>: <span class="hljs-comment"># 不执行</span><br>    <span class="hljs-keyword">pass</span><br>    <br><span class="hljs-comment"># 如果为数组、元组、字典，不为空则为真</span><br><span class="hljs-keyword">if</span> [<span class="hljs-number">1</span>]:  <span class="hljs-comment"># 执行</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> []:  <span class="hljs-comment"># 不执行</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> (<span class="hljs-number">1</span>,):  <span class="hljs-comment"># 执行</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> ():  <span class="hljs-comment"># 不执行</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> &#123;<span class="hljs-string">&#x27;sex&#x27;</span>: <span class="hljs-string">&#x27;man&#x27;</span>&#125;:  <span class="hljs-comment"># 执行</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">if</span> &#123;&#125;:  <span class="hljs-comment"># 不执行</span><br>    <span class="hljs-keyword">pass</span>     <br></code></pre></td></tr></table></figure>

<h2 id="逻辑符"><a href="#逻辑符" class="headerlink" title="逻辑符"></a>逻辑符</h2><ul>
<li><code>not</code>    结果取反，如；not True -&gt; False</li>
<li><code>and</code>    与，前后两者皆为真才为真</li>
<li><code>or</code>    或，前后两者有一个为真就为真，特性：如果第一个就为真，那第二个就不会校验，所以将运算快的条件放在第一个判断，会节省程序运行时间</li>
</ul>
<h2 id="操作符"><a href="#操作符" class="headerlink" title="操作符"></a>操作符</h2><ul>
<li><code>&lt;</code>    小于</li>
<li><code>&lt;=</code>    小于或等于</li>
<li><code>&gt;</code>    大于</li>
<li><code>&gt;=</code>    大于或等于</li>
<li><code>==</code>    等于，比较两个值是否相等</li>
<li><code>!=</code>    不等于</li>
</ul>
<h1 id="异常控制"><a href="#异常控制" class="headerlink" title="异常控制"></a>异常控制</h1><h2 id="用法"><a href="#用法" class="headerlink" title="用法"></a>用法</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> traceback<br><br><span class="hljs-keyword">try</span>：<span class="hljs-comment"># 尝试运行代码块</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-comment"># 在尝试运行期间，如果有报错，则执行此处代码,此处会捕捉所有报错</span><br><span class="hljs-comment"># 但是如果什么都捕捉，就难判断是因为什么报错，可以通过traceback来打印报错栈</span><br><span class="hljs-keyword">except</span>: <br>    traceback.print_exc()<br><span class="hljs-keyword">except</span> ValueError <span class="hljs-keyword">as</span> e:  <span class="hljs-comment"># 捕捉指定报错，非此报错不捕捉，方便程序维护</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">finally</span>: <span class="hljs-comment"># 不管是否会运行报错，都会执行的代码块，一般用来关闭连接，如：数据库连接</span><br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">else</span>:  <span class="hljs-comment"># 没想到吧，else在这里也有。当【try】的代码块正常运行无误后，会触发else</span><br>    <span class="hljs-keyword">pass</span><br></code></pre></td></tr></table></figure>

<h2 id="文件打开示例"><a href="#文件打开示例" class="headerlink" title="文件打开示例"></a>文件打开示例</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs python">file = <span class="hljs-built_in">open</span>(<span class="hljs-string">&#x27;open.txt&#x27;</span>, <span class="hljs-string">&#x27;r&#x27;</span>)<br><span class="hljs-keyword">try</span>: <br>    <span class="hljs-keyword">pass</span><br><span class="hljs-keyword">finally</span>:  <span class="hljs-comment"># 不管怎么样，都会关闭文件的连接，保证内存的干净，如果没有这一步，会有内存风险</span><br>    file.close()<br></code></pre></td></tr></table></figure>

<h2 id="with-更加优雅的try…finally"><a href="#with-更加优雅的try…finally" class="headerlink" title="with 更加优雅的try…finally"></a>with 更加优雅的try…finally</h2><blockquote>
<p>with 关键字会返回一个变量，通过as进行赋值创建<br>作用：with会在代码块运行结束后（不管是正常结束还是报错结束），都会调用对象中自带的close函数，进行文件、连接的关闭</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">&#x27;open.txt&#x27;</span>, <span class="hljs-string">&#x27;r&#x27;</span>) <span class="hljs-keyword">as</span> file:<br>    <span class="hljs-keyword">pass</span><br><span class="hljs-comment"># 不管怎么样，都会关闭文件</span><br></code></pre></td></tr></table></figure>

<h1 id="文件操作"><a href="#文件操作" class="headerlink" title="文件操作"></a>文件操作</h1><h2 id="打开一个文件"><a href="#打开一个文件" class="headerlink" title="打开一个文件"></a>打开一个文件</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># open，python自带的open函数，一般接收三个参数</span><br><span class="hljs-comment"># 第一个参数：文件路径</span><br><span class="hljs-comment"># 第二个参数：打开方式</span><br><span class="hljs-comment"># 第三个参数，编码方式，通过指定的方式传递，encoding=&#x27;utf-8&#x27;</span><br>f = <span class="hljs-built_in">open</span>(<span class="hljs-string">&#x27;xxx&#x27;</span>, <span class="hljs-string">&#x27;r&#x27;</span>, encodeing=<span class="hljs-string">&#x27;utf-8&#x27;</span>)<br></code></pre></td></tr></table></figure>

<h2 id="打开方式"><a href="#打开方式" class="headerlink" title="打开方式"></a>打开方式</h2><ul>
<li>r    以只读方式打开文件。文件的指针将会放在文件的开头。这是默认模式。</li>
<li>rb    以二进制格式打开一个文件用于只读。文件指针将会放在文件的开头。这是默认模式。一般用于非文本文件如图片等。</li>
<li>r+    打开一个文件用于读写。文件指针将会放在文件的开头。</li>
<li>rb+    以二进制格式打开一个文件用于读写。文件指针将会放在文件的开头。一般用于非文本文件如图片等。</li>
<li>w    打开一个文件只用于写入。如果该文件已存在则打开文件，并从开头开始编辑，即原有内容会被删除。如果该文件不存在，创建新文件。</li>
<li>wb    以二进制格式打开一个文件只用于写入。如果该文件已存在则打开文件，并从开头开始编辑，即原有内容会被删除。如果该文件不存在，创建新文件。一般用于非文本文件如图片等。</li>
<li>w+    打开一个文件用于读写。如果该文件已存在则打开文件，并从开头开始编辑，即原有内容会被删除。如果该文件不存在，创建新文件。</li>
<li>wb+    以二进制格式打开一个文件用于读写。如果该文件已存在则打开文件，并从开头开始编辑，即原有内容会被删除。如果该文件不存在，创建新文件。一般用于非文本文件如图片等。</li>
<li>a    打开一个文件用于追加。如果该文件已存在，文件指针将会放在文件的结尾。也就是说，新的内容将会被写入到已有内容之后。如果该文件不存在，创建新文件进行写入。</li>
<li>ab    以二进制格式打开一个文件用于追加。如果该文件已存在，文件指针将会放在文件的结尾。也就是说，新的内容将会被写入到已有内容之后。如果该文件不存在，创建新文件进行写入。</li>
<li>a+    打开一个文件用于读写。如果该文件已存在，文件指针将会放在文件的结尾。文件打开时会是追加模式。如果该文件不存在，创建新文件用于读写。</li>
<li>ab+    以二进制格式打开一个文件用于追加。如果该文件已存在，文件指针将会放在文件的结尾。如果该文件不存在，创建新文件用于读写。</li>
</ul>
<h2 id="操作方式-5"><a href="#操作方式-5" class="headerlink" title="操作方式"></a>操作方式</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 读取，mode=&#x27;r&#x27;</span><br><span class="hljs-comment"># 读取所有的内容，不建议，因为如果文件过大，会过度占用内存，甚至导致程序崩溃</span><br><span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">&#x27;open.txt&#x27;</span>, <span class="hljs-string">&#x27;r&#x27;</span>) <span class="hljs-keyword">as</span> f:<br>    all_read = f.read()<br><br><span class="hljs-comment"># 逐行读取（建议，比较节省内存，速度不快不慢）</span><br><span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">&#x27;open.txt&#x27;</span>, <span class="hljs-string">&#x27;r&#x27;</span>) <span class="hljs-keyword">as</span> f:<br>    <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">    原理讲解：</span><br><span class="hljs-string">        利用循环的特性，当读取出来的行为空，证明读取完毕，ps：回车也会算作是不为空</span><br><span class="hljs-string">    运行流程：</span><br><span class="hljs-string">        先读取第一行，开始循环，在循环中读取下一行，直到为空则中断循环</span><br><span class="hljs-string">        所以要将line = f.readlines()循环体的放在最后</span><br><span class="hljs-string">    &quot;&quot;&quot;</span><br>    line = f.readline()<br>    <span class="hljs-keyword">while</span> line:<br>        line = f.readline()<br><br><span class="hljs-comment"># 写入,mode=&#x27;w&#x27;，这是覆盖式写法，其他写法参考8.2</span><br><span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">&#x27;open.txt&#x27;</span>, <span class="hljs-string">&#x27;w&#x27;</span>) <span class="hljs-keyword">as</span> f:<br>    f.write(<span class="hljs-string">&#x27;xxx&#x27;</span>)<br></code></pre></td></tr></table></figure>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/my-blog/categories/python/" class="category-chain-item">python</a>
  
  
    <span>></span>
    
  <a href="/my-blog/categories/python/Python%E5%9F%BA%E7%A1%80/" class="category-chain-item">Python基础</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/my-blog/tags/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/">#测试开发</a>
      
        <a href="/my-blog/tags/Python%E5%9F%BA%E7%A1%80/">#Python基础</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Python基础</div>
      <div>https://walker_kwu.gitee.io/my-blog/2022/11/16/python/basic/base/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>木舟</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年11月16日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年5月23日</div>
        </div>
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="NC - 非商业性使用">
                <i class="iconfont icon-nc"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="SA - 相同方式共享">
                <i class="iconfont icon-sa"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/my-blog/2022/11/19/notes/vue/component/" title="vue组件">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">vue组件</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/my-blog/2022/11/13/notes/vue/watch/" title="Vue--watch监听器">
                        <span class="hidden-mobile">Vue--watch监听器</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <span>By 木舟</span> <i class="iconfont icon-love"></i> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/my-blog/js/events.js" ></script>
<script  src="/my-blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/my-blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/my-blog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/my-blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
